package com.seb.cc.gtou.adapter;

import java.text.DateFormat;
import java.util.Date;

import com.seb.cc.gtou.db.GTLieuDB;
import com.seb.cc.gtou.db.GTSejourDB;
import com.seb.cc.gtou.utils.DateTimeFormat;
import com.seb.cc.ttou.R;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class GTouLieuAdatpter extends CursorAdapter {
	 private final LayoutInflater mInflater;
	 
	public GTouLieuAdatpter(Context context, Cursor c, boolean autoRequery) {
		super(context, c, autoRequery);
		mInflater = LayoutInflater.from(context);
		
		// TODO Auto-generated constructor stub
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		TextView lieuDesc=(TextView)view.findViewById(R.id.textViewRowDesc);
		lieuDesc.setText(cursor.getString(cursor.getColumnIndex(GTLieuDB.GTLieuTable.DESCRIPTION)));
		
		TextView startLabel = (TextView)view.findViewById(R.id.textViewLabelDebut);
		startLabel.setText(R.string.lieuListRowFrom);
		
		Long heureDebut = cursor.getLong(cursor.getColumnIndex(GTLieuDB.GTLieuTable.HEURE_DEBUT));
		TextView sejourDebut = (TextView)view.findViewById(R.id.textViewRowDebut);
		sejourDebut.setText(DateTimeFormat.formatTime(view.getContext(),heureDebut));
		
		TextView endLabel = (TextView)view.findViewById(R.id.textViewLabelFin);
		endLabel.setText(R.string.lieuListRowTo);
		
		Long heureFin = cursor.getLong(cursor.getColumnIndex(GTLieuDB.GTLieuTable.HEURE_FIN));
		TextView sejourFin = (TextView)view.findViewById(R.id.textViewRowFin);
		sejourFin.setText(DateTimeFormat.formatTime(view.getContext(), heureFin));

	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
	     final View view = mInflater.inflate(R.layout.gtousejourrow, parent, false);
	      return view;
	}

}
